from random import randint

from utils.log import Log
from utils.raw_obj import RawObject as Obj


class Generator(Log):
    def __init__(self, count=randint(15, 50), min_val=randint(1, 20), max_val=randint(800, 1000), asc=True):
        super(Generator, self).__init__()
        self.count = count
        self.min = min_val
        self.max = max_val
        self.asc = asc

    def do(self):
        result = []
        for _ in range(self.count):
            result.append(Obj(randint(self.min, self.max), self.asc))
        return result

    def single_val(self):
        return Obj(randint(self.min, self.max), self.asc)

    def range_val(self, min_v=None, max_v=None):
        if min_v is None:
            min_v = self.min if self.asc else self.max
        if max_v is None:
            max_v = self.max if self.asc else self.min
        return Obj(randint(min(min_v, max_v), max(min_v, max_v)), self.asc)

    def segments(self):
        result = []
        for _ in range(self.count):
            o1 = Obj(randint(self.min, self.max), self.asc)
            o2 = Obj(randint(self.min, self.max), self.asc)
            result.append(sorted([o1, o2]))
        return result


if __name__ == '__main__':
    print(sorted(Generator(max_val=1000).do()))
    print(sorted(Generator(max_val=1000, asc=False).do()))
